home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / ASCII2.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  187 lines

  1. //--------------------------------------------------------------------
  2. // ASCII2.AML
  3. // 2-Dimensional Ascii chart, (C) 1993-1996 by nuText Systems
  4. //
  5. // (See Ascii2.dox for user help)
  6. //
  7. // This macro displays a two-dimensional Ascii chart and shows character
  8. // codes in decimal, hex, octal, and binary. The Ascii character at the
  9. // cursor can be entered into the text of the current edit window.
  10. //
  11. // Usage:
  12. //
  13. // Select this macro from the Macro List (on the Macro menu), or run it
  14. // from the macro picklist <shift f12>.
  15. //--------------------------------------------------------------------
  16.  
  17. include bootpath "define.aml"
  18.  
  19. // colors
  20. constant ascii_border_color  = color white on gray
  21. constant ascii_flash_color   = color brightgreen on gray
  22. constant ascii_title_color   = color white on magenta
  23. constant ascii_text_color    = color black on gray
  24.  
  25. variable x, y, x2, asciival
  26.  
  27. // keep this object resident
  28. resident ON
  29. settype "win"
  30.  
  31. // create the ascii chart window
  32. createwindow
  33. setframe "bn"
  34. setcolor  border_color        ascii_border_color
  35. setcolor  border_flash_color  ascii_flash_color
  36. setcolor  north_title_color   ascii_title_color
  37. setcolor  text_color          ascii_text_color
  38. settitle "2-D Ascii Chart - press <enter> to select"
  39. setwinctrl '≡'
  40. width = 47
  41. height = 18
  42. // center the window
  43. ox = (getvidcols - width) / 2
  44. oy = (getvidrows - height) / 2
  45. sizewindow ox oy ox + width oy + height "ad"
  46. setborder "1i"
  47. setshadow 2 1
  48.  
  49. // draw the ascii chart
  50. for y = 0 to 15 do
  51.   for x = 0 to 15 do
  52.     writestr (char 32 y * 16 + x 32)
  53.   end
  54.   writeline
  55. end
  56.  
  57. // get last position
  58. asciival = _ascii2
  59. x = asciival mod 16
  60. y = asciival / 16
  61.  
  62. showcursor 50 99
  63.  
  64. private function draw
  65.   if x2 then
  66.     // clear the bracket cursor
  67.     writestr ' ' '' x2 - 1
  68.     writestr ' ' '' x2 + 1
  69.   end
  70.  
  71.   asciival = y * 16 + x
  72.  
  73.   // write ascii info at the bottom of the chart
  74.   writestr ' char=' + (char asciival) +
  75.            '  dec=' + asciival:3:'0' +
  76.            '  hex=' + (base asciival 16):2:'0' +
  77.            '  oct=' + (base asciival 8):3:'0' +
  78.            '  bin=' + (base asciival 2):8:'0' +
  79.            '':8
  80.            (color white on magenta) 1 17
  81.  
  82.   // move the cursor to the appropriate ascii cell
  83.   x2 = x * 3 + 2
  84.   gotoxy x2 y + 1
  85.  
  86.   // write the bracket [ ] cursor
  87.   writestr '[' (color white on gray) x2 - 1
  88.   writestr ']' (color white on gray) x2 + 1
  89.   gotoxy x2 y + 1
  90. end
  91.  
  92. draw
  93.  
  94. event <destroy>
  95.   // save current position for next time
  96.   prf.ascii2 = asciival
  97.   // pass on to 'close' function in win object
  98.   close
  99. end
  100.  
  101. // mouse click
  102. event <lbutton>
  103.   pass
  104.   case getregion
  105.     // client area
  106.     when 1
  107.       pass
  108.       if virtorow <= 16 then
  109.         y = (virtorow - 1) mod 16
  110.       end
  111.       x = (virtocol - 1) / 3
  112.       draw
  113.   end
  114. end
  115.  
  116. event <ldouble>
  117.   call <enter>
  118. end
  119.  
  120. event <move>
  121.   pass
  122.   if (button? 1) and getregion == 1 then
  123.     send <lbutton>
  124.   end
  125. end
  126.  
  127. key <esc>
  128.   destroyobject
  129. end
  130.  
  131. function '≡'
  132.   destroyobject
  133. end
  134.  
  135. // macro help
  136. macrofile = arg 1
  137. key <f1>
  138.   helpmacro macrofile
  139. end
  140.  
  141. // enter the ascii character in an edit window and exit
  142. key <enter>
  143.   destroyobject
  144.   queue "write" (char asciival)
  145. end
  146.  
  147. // move the cursor around in the chart
  148. key <left>
  149.   x = if? x (x - 1) 15
  150.   draw
  151. end
  152.  
  153. key <right>
  154.   x = (x + 1) mod 16
  155.   draw
  156. end
  157.  
  158. key <up>
  159.   y = if? y (y - 1) 15
  160.   draw
  161. end
  162.  
  163. key <down>
  164.   y = (y + 1) mod 16
  165.   draw
  166. end
  167.  
  168. key <home>
  169.   x = 0
  170.   draw
  171. end
  172.  
  173. key <end>
  174.   x = 15
  175.   draw
  176. end
  177.  
  178. key <ctrl home>
  179.   y = 0
  180.   draw
  181. end
  182.  
  183. key <ctrl end>
  184.   y = 15
  185.   draw
  186. end
  187.